//Copyright (c) 2010, Goodwine & Tibia ML
//Licensed under new BSD License.

// Adds links to the characters or worlds given the case in "Who is Online" section.
var list = document.getElementsByTagName('tbody');
for (var i = 1; i < list.length; i++)
{
	if(opLinkPages.world) {
		if(list[i].innerHTML.match(/class="white">Level<\/a>/ig))
		{
			link_chars(list[i].getElementsByTagName('tr'));
			break;
		}
		else if (list[i].innerHTML.match(/<b>Additional Information<\/b>/ig))
		{
			link_worlds(list[i].getElementsByTagName('tr'));
			break;
		}
	}
}

function link_chars(rows)
{
	for (var i = 0; i < rows.length; i++)
	{
		var pattern = /subtopic=characters.*?name=.*?>(.*?)</img;
		while (x = pattern.exec(rows[i].firstChild.innerHTML))
			linkCharacter(rows[i].firstChild, x[1], 'right');
	}
}

function link_worlds(rows)
{
	for (var i = 0; i < rows.length; i++)
	{
		var pattern = /subtopic=worlds.*?world=.*?>(.*?)</img;
		while (x = pattern.exec(rows[i].firstChild.innerHTML))
		{
			world = x[1].replace(/(\xa0|&#160;|&nbsp;| )/g, '+');
			linkWorlds(rows[i].firstChild, world, 'right');
		}
	}
}